package org.mozhu.mboot.admin.maintain.email.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.joda.time.LocalDateTime;
import org.mozhu.mboot.admin.Constants;
import org.mozhu.mboot.core.data.entity.BaseEntity;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;

@Entity
@Table(name = "maintain_email_validation")
@Data
@EqualsAndHashCode(callSuper = true)
public class EmailValidation extends BaseEntity {

    private String email;
    private String type;
    private String code;

    @DateTimeFormat(pattern = Constants.DATE_TIME_FORMAT_PATTERN)
    @Temporal(TemporalType.TIMESTAMP)
    private Date expiryDate;


    public boolean isExpired() {
        return new LocalDateTime().isAfter(new LocalDateTime(getExpiryDate()));
    }

}
